package com.springcloud.auth.authorization.exception;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.springcloud.common.core.entity.R;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.security.oauth2.common.exceptions.OAuth2Exception;

@EqualsAndHashCode(callSuper = true)
@Data
@JsonSerialize(using = CustomOauthExceptionSerializer.class)
class CustomOauthException extends OAuth2Exception {

    private final R result;

    CustomOauthException(OAuth2Exception oAuth2Exception) {
        super(oAuth2Exception.getSummary(), oAuth2Exception);
        this.result = R.failed(AuthErrorType.valueOf(oAuth2Exception.getOAuth2ErrorCode().toUpperCase()));
    }
}
